/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dawnland03.model.task.impl;

import dawnland03.model.action.parameter.ActionOutputParam;
import dawnland03.model.task.Task;
import dawnland03.model.task.TaskCondition;

/**
 * @author Petru Obreja (obrejap@yahoo.com)
 */
public class MoveToTaskCondition implements TaskCondition {

    private Integer times = 0;

    private final Integer nrOfIterations;

    public MoveToTaskCondition(Integer nrOfIterations) {
        this.nrOfIterations = nrOfIterations;
    }

    public void isTaskCompleted(Task currentTask) {

        Boolean taskCompleted = (Boolean) currentTask.getOutputParameters().getOutputParameter(ActionOutputParam.COMPLETED);
        if (taskCompleted == true) {
            //do nothing
        } else {
            //cancel or retry the task
            times++;
            if (times < nrOfIterations) {
                currentTask.getParentTask().duplicateTaskAndAddFirst(currentTask);
            } else {
                currentTask.getParentTask().cancelTask();
            }
        }
    }

}
